﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace PivotApp1
{
    public partial class MainPage : PhoneApplicationPage
    {
        int stn1, stn2;
        int flag = -1; //i ->initial load, t->navigated here from taxi page, a->navigated here from auto page
        
        double auto_dist = 0.0;
        double auto_rem = 0.0;
        double fare = 0.0;

        double taxi_dist = 0.0;
        double taxi_rem = 0.0;
        double Meru_fare = 0.0;
        double Quick_fare = 0.0;
        double Easy_fare = 0.0;
        double universal_fare = 0.0;

        String destination = "too";
        String source = "frm";

        // Constructor
        public MainPage()
        {
            InitializeComponent();

            // Set the data context of the listbox control to the sample data
            DataContext = App.ViewModel;
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        }
        

        // Load data for the ViewModel Items
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            if (!App.ViewModel.IsDataLoaded)
            {
                App.ViewModel.LoadData();
            }
            
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            

            /*if (flag == -1)
            {
                auto_textBox1.Text = Convert.ToString(Double.Parse("0.0"));
                taxi_textBox1.Text = Convert.ToString(Double.Parse("0.0"));
            }

            if (flag != -1)
            {
                flag = Int16.Parse(NavigationContext.QueryString["flag"]);
            }

            if (flag == 1)
            {
                auto_textBox1.Text = NavigationContext.QueryString["dist_a"];
            }

            if (flag == 2)
            {
                taxi_textBox1.Text = NavigationContext.QueryString["dist_t"];
            }*/

           
        }

        private void button1_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            //if (auto_textBox1.Text.Trim().Length == 0)
            //{
            //    NavigationService.Navigate(new Uri("/Auto_Info.xaml", UriKind.RelativeOrAbsolute));
            //}
            //else
            //{
            //flag = 1;                
            NavigationService.Navigate(new Uri("/Auto_Info.xaml?distance=" + auto_textBox1.Text +"&flag="+flag, UriKind.RelativeOrAbsolute));
            //}
        }


        private void button2_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            //if (taxi_textBox1.Text.Trim().Length == 0)
            //{
            //    NavigationService.Navigate(new Uri("/Taxi_Info.xaml", UriKind.RelativeOrAbsolute));
            //}
            //else
            //{
            //flag = 2;
            NavigationService.Navigate(new Uri("/Taxi_Info.xaml?distance=" + auto_textBox1.Text + "&flag=" + flag, UriKind.RelativeOrAbsolute));
                
            //}
        }

        private void button3_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Metro_Info.xaml", UriKind.RelativeOrAbsolute));
        }

        private void auto_textBox1_TextChanged(object sender, TextChangedEventArgs e)
        {
            taxi_textBox1.Text = auto_textBox1.Text;
            auto_calculation();
        }

        private void auto_luggage_Checked(object sender, RoutedEventArgs e)
        {
            auto_calculation();
        }

        private void auto_luggage_UnChecked(object sender, RoutedEventArgs e)
        {
            auto_calculation();
        }

        private void auto_calculation()
        {
            
            if (auto_textBox1.Text.Trim().Length == 0)
            {
                auto_dist = 0.0;
            }

            else
            {
                auto_dist = float.Parse(auto_textBox1.Text);
            }

            if (auto_dist <= 0.0)
            {
                fare = 0.0;
                
                auto_textBox3.Text = Convert.ToString(fare);
                
            }

            if (auto_dist <= 2.0 && auto_dist > 0.0)
            {
                fare = 19.0;
                if ((bool)auto_night_charge_on.IsChecked)
                {
                    fare = fare + (fare / 4);  //25% EXTRA CHARGE FOR NIGHT.
                }

                if ((bool)auto_luggage_on.IsChecked)
                {
                    fare = fare + 7.5;  //Rs 7.5 EXTRA CHARGE FOR Luggage.
                }
                fare = Math.Round(fare, 2);
                auto_textBox3.Text = Convert.ToString(fare);
            }

            if (auto_dist > 2.0)
            {
                auto_rem = auto_dist - 2.0;
                fare = 19.0 + (auto_rem * 6.5);

                if ((bool)auto_night_charge_on.IsChecked)
                {
                    fare = fare + (fare / 4);  //25% EXTRA CHARGE FOR NIGHT.
                }

                if ((bool)auto_luggage_on.IsChecked)
                {
                    fare = fare + 7.5;  //Rs 7.5 EXTRA CHARGE FOR Luggage.
                }
                fare = Math.Round(fare, 2);
                auto_textBox3.Text = Convert.ToString(fare);
            }
        }

        // /////////////////////////////////////////////////////////////////////////////////////

        private void taxi_textBox1_TextChanged(object sender, TextChangedEventArgs e)
        {
            auto_textBox1.Text = taxi_textBox1.Text;
            taxi_calculation();
        }


        private void taxi_calculation()
        {
            
            if (taxi_textBox1.Text.Trim().Length == 0)
            {
                taxi_dist = 0.0;
            }

            else
            {
                taxi_dist = float.Parse(taxi_textBox1.Text);
            }


            if (taxi_dist <= 0.0)
            {
                universal_fare = 0.0;
                MeruCab_Fare.Text = Convert.ToString(universal_fare);
                QuickCab_Fare.Text = Convert.ToString(universal_fare);
                EasyCab_Fare.Text = Convert.ToString(universal_fare);
            }

            if (taxi_dist > 0.0 && taxi_dist <= 1.0)
            {
                //Meru Cabs
                Meru_fare = 20.0;
                if ((bool)taxi_night_charge_on.IsChecked)
                {
                    Meru_fare = Meru_fare + (Meru_fare / 4);  //25% EXTRA CHARGE FOR NIGHT.
                }
                Meru_fare = Math.Round(Meru_fare, 2);
                MeruCab_Fare.Text = Convert.ToString(Meru_fare);


                //Quick Cabs
                Quick_fare = 10.0;
                if ((bool)taxi_night_charge_on.IsChecked)
                {
                    Quick_fare = Quick_fare + (Quick_fare / 4);  //25% EXTRA CHARGE FOR NIGHT.
                }
                if ((bool)taxi_AC_btn.IsChecked)
                {
                    Quick_fare = Quick_fare + 10;  //Rs 10 EXTRA CHARGE FOR AC
                }
                Quick_fare = Math.Round(Quick_fare, 2);
                QuickCab_Fare.Text = Convert.ToString(Quick_fare);
                


                //Easy Cabs
                Easy_fare = 20.0;
                if ((bool)taxi_night_charge_on.IsChecked)
                {
                    Easy_fare = Easy_fare + (Easy_fare / 4);  //25% EXTRA CHARGE FOR NIGHT.
                }
                Easy_fare = Math.Round(Easy_fare, 2);
                EasyCab_Fare.Text = Convert.ToString(Easy_fare);

            }


            if (taxi_dist > 1.0)
            {
                taxi_rem = taxi_dist - 1.0;
                //Meru Cabs
                Meru_fare = 20.0 + taxi_rem * 20.0;

                if ((bool)taxi_night_charge_on.IsChecked)
                {
                    Meru_fare = Meru_fare + (Meru_fare / 4);  //25% EXTRA CHARGE FOR NIGHT.
                }
                Meru_fare = Math.Round(Meru_fare, 2);
                MeruCab_Fare.Text = Convert.ToString(Meru_fare);


                //Quick Cabs
                Quick_fare = 10.0 + taxi_rem * 20.0;
                
                if ((bool)taxi_night_charge_on.IsChecked)
                {
                    Quick_fare = Quick_fare + (Quick_fare / 4);  //25% EXTRA CHARGE FOR NIGHT.
                }
                if ((bool)taxi_AC_btn.IsChecked)
                {
                    Quick_fare = Quick_fare + 10;  //Rs 10 EXTRA CHARGE FOR AC
                }
                Quick_fare = Math.Round(Quick_fare, 2);
                QuickCab_Fare.Text = Convert.ToString(Quick_fare);



                //Easy Cabs
                Easy_fare = 20.0 + taxi_rem * 20.0;
                if ((bool)taxi_night_charge_on.IsChecked)
                {
                    Easy_fare = Easy_fare + (Easy_fare / 4);  //25% EXTRA CHARGE FOR NIGHT.
                }
                Easy_fare = Math.Round(Easy_fare, 2);
                EasyCab_Fare.Text = Convert.ToString(Easy_fare);

            }
        }

        private void taxi_AC(object sender, RoutedEventArgs e)
        {
            taxi_calculation();
        }

        private void taxi_nonAC(object sender, RoutedEventArgs e)
        {
            taxi_calculation();
        }

        private void taxi_night_charge_on_Checked(object sender, RoutedEventArgs e)
        {
            taxi_calculation();
        }

        private void taxi_night_charge_on_UnChecked(object sender, RoutedEventArgs e)
        {
            taxi_calculation();
        }
        
        private void auto_night_charge_on_Checked(object sender, RoutedEventArgs e)
        {
            auto_calculation();
        }

        private void auto_night_charge_on_UnChecked(object sender, RoutedEventArgs e)
        {
            auto_calculation();
        }

        private void auto_textBox1_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            if (auto_textBox1.Text == "0")
            {
                auto_textBox1.Text = "";
            }
            
        }

        private void taxi_textBox1_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            if (taxi_textBox1.Text == "0")
            {
                taxi_textBox1.Text = "";
            }
            
        }

      

        private void To_myListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            recalculate_metro_fare_t();
        }

        private void From_myListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            recalculate_metro_fare_f();
        }

        private void recalculate_metro_fare_f()
        {
           // metroFareBox.Text = Convert.ToString("f");
        }

        private void recalculate_metro_fare_t()
        {
            //metroFareBox.Text = Convert.ToString("t");
        }

        private void yo()
        {
            int A = numbers[stn1, stn2];
            
            String s = "";
            s = A.ToString();

            metroFareBox.Text = s;
        }

        int[,] numbers = new int[,] { { 8, 21, 21, 22, 18, 16, 25, 27, 22, 29, 20, 20, 19, 15, 19, 19, 23, 25, 19, 18 },
                                      { 21, 8, 18, 21, 12, 16, 15, 25, 10, 21, 20, 16, 16, 15, 21, 21, 21, 15, 16, 15 },
                                      { 21, 18, 8, 15, 15, 16, 22, 25, 19, 27, 26, 16, 16, 16, 21, 15, 22, 22, 16, 15 },
                                      { 22, 21, 15, 8, 18, 18, 25, 27, 22, 28, 26, 18, 19, 19, 23, 18, 23, 23, 19, 16 },
                                      { 18, 12, 15, 18, 8, 12, 18, 22, 15, 23, 12, 12, 15, 10, 19, 19, 18, 18, 15, 10 },
                                      { 16, 16, 16, 18, 12, 8, 21, 23, 18, 25, 20, 15, 8, 15, 16, 19, 19, 19, 15, 10 },
                                      { 25, 15, 22, 25, 18, 21, 8, 28, 12, 16, 28, 21, 21, 19, 25, 25, 23, 8, 21, 19 },
                                      { 27, 25, 25, 27, 22, 23, 28, 8, 27, 30, 28, 21, 23, 23, 28, 28, 28, 28, 19, 22 },
                                      { 22, 10, 19, 22, 15, 18, 12, 27, 8, 19, 30, 18, 18, 16, 22, 23, 21, 12, 18, 16 },
                                      { 29, 21, 27, 28, 23, 25, 16, 30, 19, 8, 19, 20, 20, 20, 21, 22, 28, 18, 27, 25 },
                                      { 20, 20, 26, 26, 12, 20, 28, 28, 20, 19, 8, 20, 20, 20, 21, 22, 22, 30, 24, 30 },
                                      { 20, 16, 16, 18, 12, 15, 21, 21, 18, 20, 20, 8, 15, 20, 19, 19, 21, 21, 8, 10 },
                                      { 19, 16, 16, 19, 15,  8, 21, 23, 18, 20, 20, 15, 8,  15, 16, 21, 21, 21, 15, 12 },
                                      { 15, 15, 16, 19, 10, 15, 19, 23, 17, 20, 20, 20, 15, 8, 21, 21, 19, 19, 15, 12 },
                                      { 19, 21, 21, 23, 19, 16, 25, 28, 22, 21, 21, 19, 16, 21, 8, 25, 25, 25, 21, 18 },
                                      { 19, 21, 15, 18, 19, 19, 25, 28, 23, 22, 22, 19, 21, 21, 25, 8, 25, 25, 21, 18 },
                                      { 23, 21, 22, 23, 18, 19, 23, 28, 21, 28, 22, 21, 21, 19, 25, 25, 8, 23, 21, 18 },
                                      { 25, 15, 22, 23, 18, 19,  8, 28, 12, 18, 30, 21, 21, 19, 25, 25, 23, 8, 21, 18 },
                                      { 19, 16, 16, 19, 15, 15, 21, 19, 18, 27, 24, 8, 15, 15, 21, 21, 21, 21, 8, 12 },
                                      { 18, 15, 15, 16, 10, 10, 19, 22, 16, 25, 30, 10, 12, 12, 18, 18, 18, 18, 12, 8 } };



        private void F_AdarshNagar_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn1 = 0;
            //metroFareBox.Text = "0";
            yo();
        }

        private void F_AIIMS_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn1 = 1;
            yo();
            //metroFareBox.Text = "0";
        }
        private void F_Akshardham_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn1 = 2;
            yo();
        }

        private void F_AnandVihar_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn1 = 3;
            yo();
        }

        private void F_CentralSecretariat_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn1 = 4;
            yo();
        }

        private void F_ChandniChowk_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn1 = 5;
            yo();
        }

        private void F_Chhatarpur_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn1 = 6;
            yo();
        }

        private void F_Dwarka_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn1 = 7;
            yo();
        }

        private void F_HauzKhas_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn1 = 8;
            yo();
        }

        private void F_IFFCOChowk_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn1 = 9;
            yo();
        }

        private void F_IGIAirport_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn1 = 10;
            yo();
        }

        private void F_KarolBagh_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn1 = 11;
            yo();
        }

        private void F_KashmereGate_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn1 = 12;
            yo();
        }

        private void F_KhanMarket_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn1 = 13;
            yo();
        }

        private void F_NetajiSubhashPlace_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn1 = 14;
            yo();
        }

        private void F_NoidaSector18_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn1 = 15;
            yo();
        }

        private void F_Okhla_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn1 = 16;
            yo();
        }

        private void F_QutabMinar_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn1 = 17;
            yo();
        }

        private void F_RajendraPlace_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn1 = 18;
            yo();
        }

        private void F_RajivChowk_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn1 = 19;
            yo();
        }




        private void T_AdarshNagar_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn2 = 0;
            yo();
        }
        private void T_AIIMS_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn2 = 1;
            yo();

        }

        private void T_Akshardham_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn2 = 2;
            yo();

        }

        private void T_AnandVihar_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn2 = 3;
            yo();
        }




        private void T_CentralSecretariat_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn2 = 4;
            yo();
        }

        private void T_ChandniChowk_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn2 = 5;
            yo();
        }

        private void T_Chhatarpur_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn2 = 6;
            yo();
        }

        private void T_Dwarka_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn2 = 7;
            yo();
        }

        private void T_HauzKhas_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn2 = 8;
            yo();
        }

        private void T_IFFCOChowk_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn2 = 9;
            yo();
        }

        private void T_IGIAirport_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn2 = 10;
            yo();
        }

        private void T_KarolBagh_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn2 = 11;
            yo();
        }

        private void T_KashmereGate_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn2 = 12;
            yo();
        }

        private void T_KhanMarket_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn2 = 13;
            yo();
        }

        private void T_NetajiSubhashPlace_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn2 = 14;
            yo();
        }

        private void T_NoidaSector18_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn2 = 15;
            yo();
        }

        private void T_Okhla_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn2 = 16;
            yo();
        }

        private void T_QutabMinar_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn2 = 17;
            yo();
        }

        private void T_RajendraPlace_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn2 = 18;
            yo();
        }

        private void T_RajivChowk_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            stn2 = 19;
            yo();
        }

        

        

        

        

        /*private void F_Akshardham_Tap(object sender, GestureEventArgs e)
        {
            stn1 = 1;
            metroFareBox.Text = "8";
        }

        private void F_AnandVihar_Tap(object sender, GestureEventArgs e)
        {

        }

        private void F_ArjanGarh_Tap(object sender, GestureEventArgs e)
        {

        }

        private void F_AshokParkMain_Tap(object sender, GestureEventArgs e)
        {

        }

        private void F_Azadpur_Tap(object sender, GestureEventArgs e)
        {

        }

        private void F_Badarpur_Tap(object sender, GestureEventArgs e)
        {

        }

        private void F_BarakhambhaRoad_Tap(object sender, GestureEventArgs e)
        {

        }

        private void F_BotanicalGarden_Tap(object sender, GestureEventArgs e)
        {

        }

        private void F_CentralSecretariat_Tap(object sender, GestureEventArgs e)
        {

        }

        private void F_ChandniChowk_Tap(object sender, GestureEventArgs e)
        {

        }

        private void F_Chhatarpur_Tap(object sender, GestureEventArgs e)
        {

        }

        private void F_ChawriBazar_Tap(object sender, GestureEventArgs e)
        {

        }

        private void F_CivilLines_Tap(object sender, GestureEventArgs e)
        {

        }

        private void F_DelhiAerocity_Tap(object sender, GestureEventArgs e)
        {

        }

        private void F_DhaulaKuan_Tap(object sender, GestureEventArgs e)
        {

        }

        private void F_DilshadGarden_Tap(object sender, GestureEventArgs e)
        {

        }

        private void F_Dwarka_Tap(object sender, GestureEventArgs e)
        {

        }

        private void F_DwarkaMor_Tap(object sender, GestureEventArgs e)
        {

        }

        private void F_DwarkaSector10_Tap(object sender, GestureEventArgs e)
        {

        }

        private void F_DwarkaSector11_Tap(object sender, GestureEventArgs e)
        {

        }

        private void F_DwarkaSector12_Tap(object sender, GestureEventArgs e)
        {

        }

        private void F_DwarkaSector13_Tap(object sender, GestureEventArgs e)
        {

        }

        private void F_DwarkaSector14_Tap(object sender, GestureEventArgs e)
        {

        }

        private void F_DwarkaSector21_Tap(object sender, GestureEventArgs e)
        {

        }

        private void F_DwarkaSector8_Tap(object sender, GestureEventArgs e)
        {

        }

        private void F_DwarkaSector9_Tap(object sender, GestureEventArgs e)
        {

        }

        private void F_Ghitorni_Tap(object sender, GestureEventArgs e)
        {

        }

        private void F_GovindPuri_Tap(object sender, GestureEventArgs e)
        {

        }

        private void F_GreenPark_Tap(object sender, GestureEventArgs e)
        {

        }*/




 
        
    }
}